import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import './element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import { createI18n }  from 'vue-i18n';
import messages from './utils/messages.js';

const app = createApp(App)


async function fetchData() {
  try {
    const response = await axios.get('config.json');
    const jsonData = response.data;
    return jsonData.pageTitle
  } catch (error) {
    console.error('Error fetching config.json:', error);
  }
}
router.beforeEach(async(to, from, next) => {
  document.title = await fetchData() || 'AI助手';
  next();
});

const i18n = new createI18n({
  locale: 'en',  // 设置默认的语言
  messages: messages
});

app.use(ElementPlus)
app.use(router)
app.use(i18n)

// app.config.globalProperties.$http = axios
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.mount('#app')